package com.cloud.workTest;

import org.junit.Test;

import java.util.*;
import java.util.function.BiFunction;

public class Jdk8Test {
    @Test
    public void lambdaTest(){
        List<Integer> list = Arrays.asList(1, 2, 10, 8);
        Collections.sort(list, (s1, s2) -> Integer.compare(s1, s2));
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        System.out.println(Integer.compare(3, 9));
        System.out.println(list);
    }

    @Test
    public void methodReferenceTest(){
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "shuchuanbiao");
        map.put(2, "shuchuanbiao");
        map.merge(1, "xieqingping", (count, incr) -> count + incr);
        map.merge(2, "zhuyidong", new BiFunction() {
            @Override
            public Object apply(Object o, Object o2) {
                return "method";
            }
        });
        System.out.println(map.get(1));
        System.out.println(map.get(2));
    }
}
